"""
class list([iterable])
可以用多种方式构建列表：
使用一对方括号来表示空列表: []
使用方括号，其中的项以逗号分隔: [a], [a, b, c]
使用列表推导式: [x for x in iterable]
使用类型的构造器: list() 或 list(iterable)
 """


fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana']
fruits.count('apple') # 2
fruits.count('tangerine') #0
fruits.index('banana')# 3
fruits.index('banana', 4)  # Find next banana starting at position 4 6
fruits.reverse() # ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange']
fruits.sort() #['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', 'pear']
fruits.pop() #'pear'

squares = []
for x in range(10):
    squares.append(x**2)

# squares   [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

# 将一个列表中的每个数字乘以2
squares = [x**2 for x in range(10)]
squares = list(map(lambda x: x**2, range(10)))


combs = []
for x in [1,2,3]:
    for y in [3,1,4]:
        if x != y:
            combs.append((x, y))

# combs [(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]
combs = [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]


matrix = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
    [9, 10, 11, 12],
]
transposed = []
for i in range(4):
    transposed.append([row[i] for row in matrix])

# transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]
transposed  = [[row[i] for row in matrix] for i in range(4)]

transposed = []
for i in range(4):
    # the following 3 lines implement the nested listcomp
    transposed_row = []
    for row in matrix:
        transposed_row.append(row[i])
    transposed.append(transposed_row)

# transposed [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]

transposed = list(zip(*matrix))
# [(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]


a = [-1, 1, 66.25, 333, 333, 1234.5]
del a[0]
# a  [1, 66.25, 333, 333, 1234.5]
del a[2:4]
# a [1, 66.25, 1234.5]
del a[:]
# a []